﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class tmp_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string sql = @"
SELECT [Name]
      ,[MobileNo]
      ,[Email]
      ,[IssuedDate]
      ,[ID]
  FROM [BelmonteDB].[dbo].[Table_2]
";
            DataSet ds = CommonManager.SQLExec(sql);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string issueDate = dr["IssuedDate"].ToString();
                issueDate = issueDate.Split('/')[2] + "-" + issueDate.Split('/')[0] + "-" + issueDate.Split('/')[1];

                sql = @"
INSERT INTO [BelmonteDB].[dbo].[Pos_Customer]
           ([CardNo]
           ,[Signature]
           ,[CustomerName]
           ,[ReferenceID]
           ,[Address]
           ,[Mobile]
           ,[Phone]
           ,[DiscountPersent]
           ,[Note]
           ,[ExtraFiled1]
           ,[ExtraFiled2]
           ,[ExtraFiled3]
           ,[ExtraFiled4]
           ,[ExtraFiled5]
           ,[AddedBy]
           ,[AddedDate]
           ,[UpdatedBy]
           ,[UpdatedDate]
           ,[RowSatatusID]
           ,[DateofBirth]
           ,[ApplicationDate]
           ,[CardIssueDate]
           ,[ExpireDate]
           ,[CardType]
           ,[ApprovedBy])
     VALUES
           (
           '"+dr["ID"].ToString()+@"'--<CardNo, varchar(12),>
           ,''--<Signature, nvarchar(256),>
           ,'" + dr["Name"].ToString() + @"'--<CustomerName, varchar(50),>
           ,0--<ReferenceID, int,>
           ,''--<Address, varchar(50),>
           ,'" + dr["MobileNo"].ToString() + @"'--<Mobile, varchar(20),>
           ,'" + dr["Email"].ToString() + @"'--<Phone, varchar(20),>
           ,10--<DiscountPersent, decimal(5,2),>
           ,''
           ,''--<ExtraFiled1, nvarchar(256),>
           ,''--<ExtraFiled2, nvarchar(256),>
           ,''--<ExtraFiled3, nvarchar(256),>
           ,''--<ExtraFiled4, nvarchar(256),>
           ,''--<ExtraFiled5, nvarchar(256),>
           ,1
           ,GETDATE()
           ,1
           ,GETDATE()
           ,1
           ,GETDATE()
           ,GETDATE()
           ,'" + issueDate + @"'
           ,GETDATE()
           ,''
           ,'')
";
                CommonManager.SQLExec(sql);
            }

        }
    }
}